var audio = function() {};

audio.prototype.error_callback = function(msg) {
    console.log("Javascript Callback Error: " + JSON.stringify(msg));
}

audio.prototype.call_native = function(name, args, callback) {
    var ret = cordova.exec(callback, this.error_callback, "audio", name, args);
    return ret;
}

// 开始录制
audio.prototype.startRecordingAudio = function(callback) {
    var data = [];
    this.call_native('startRecordingAudio', data, callback);
}

// 停止录制
audio.prototype.stopRecordingAudio = function(args, callback) {
    var data = [args];
    this.call_native('stopRecordingAudio', data, callback);
}

// 播放录音
audio.prototype.playAudio = function(args, callback) {
    var data = [args];
    this.call_native('playAudio', data, callback);
}

// 停止播放
audio.prototype.stopAudio = function(args, callback) {
    var data = [args];
    this.call_native('stopAudio', data, callback);
}


if (!window.plugins) {
    window.plugins = {};
}

if (!window.plugins.audio) {
    window.plugins.audio = new audio();
}
module.exports = new audio();
